package learnMethod

import (
	"fmt"
	"math/rand"
	"time"
)

func ArrayTest01() {
	/*    var a [5]int

	      a[0]=1
	      a[1]=1
	      a[2]=1
	      a[3]=1
	      a[4]=1
	      fmt.Printf("a的地址%p\n",&a)
	      fmt.Printf("a的值是%v\n",*(&a))
	      fmt.Printf("a[0]的地址%p\n,a[1]的地址%p\n,a[2]的地址%p\n,a[3]的地址%p\n,a[4]的地址%p\n",&a[0],&a[1],&a[2],&a[3],&a[4])


	      for i := 0; i < len(a); i++ {
	          fmt.Printf("a[%d]的地址%p,值为%d\n",i,&i,a[i])
	      }

	      for i, i2 := range a {
	          fmt.Printf("下标：%d,值：%d\n",i,i2)
	      }*/
	/*
	   var arr [5]int
	   len :=len(arr)
	   rand.Seed(time.Now().UnixNano())

	   for i := 0; i < len; i++ {
	       arr[i]=rand.Intn(100)
	   }
	   fmt.Println("反转前：",arr)
	   temp :=0

	   for i := 0; i < len/2; i++ {
	       temp=arr[len-1-i]
	       arr[len-1-i]=arr[i]
	       arr[i]=temp
	   }*/
	var arr [5]int
	rand.Seed(time.Now().UnixNano())

	for i := 0; i < len(arr); i++ {
		arr[i] = rand.Intn(100)
	}
	fmt.Println("反转后：", arr)

	slice := arr[1:4]
	fmt.Println(arr)
	fmt.Println(slice)
	fmt.Println(len(slice))
	fmt.Println(cap(slice))

}

func MaxVal(arr [10000000]int) {

	for i := 0; i < 10000000; i++ {
		arr[i] = rand.Intn(10000000)
	}
	maxVal := arr[0]
	for i := 1; i < len(arr); i++ {
		if arr[i] > maxVal {
			maxVal = arr[i]
		}
	}
	fmt.Printf("最大值为：%v\n", maxVal)

}

func TwoPointSearch(arr [10000000]int) {
	len := len(arr)
	left := 0
	right := len - 1
	var maxVal int
	for i := 0; i < len/2; i++ {
		if arr[left] > maxVal {
			maxVal = arr[left]
		}
		if arr[right] > maxVal {
			maxVal = arr[right]
		}
		left++
		right--
	}
	fmt.Printf("最大值为：%v\n", maxVal)
}
func TwoPoint3Search(arr [1000000]int) {
	len := len(arr)
	left := 0
	right := len - 1
	var maxVal int
	for i := 0; i < len/2; i++ {
		if arr[left] > maxVal {
			maxVal = arr[left]
		}
		if arr[right] > maxVal {
			maxVal = arr[right]
		}
		left++
		right--
	}
	fmt.Printf("最大值为：%v\n", maxVal)
}

func SliceTets03() {
	var arr []int = []int{10, 20, 30, 40, 50}
	sliceArr01 := arr[1:4]
	var sliceArr02 []int = []int{10, 20, 30, 40, 50}

	fmt.Println("sliceArr01")
	for i := 0; i < len(sliceArr01); i++ {
		fmt.Println(sliceArr01[i])
	}
	fmt.Println("sliceArr02")
	for i := 0; i < len(sliceArr02); i++ {
		fmt.Println(sliceArr02[i])
	}
	sliceArr03 := sliceArr01[2:3]
	sliceArr03[0] = 100
	fmt.Println("sliceArr03")
	for i := 0; i < len(sliceArr03); i++ {
		fmt.Println(sliceArr03[i])
	}

	fmt.Println(len(sliceArr03))
	fmt.Println(cap(sliceArr03))
}
